/**
 * Created by Administrator on 2017/6/16.
 */
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function () {
            oldonload();
            func();
        }
    }

}
function addClass(element, value) {
    if (!element.className) {
        element.className = value;
    }
    else {
        var newClassName = element.className;
        newClassName = +' ';
        newClassName += value;
        element.className = newClassName;
    }
}
function insertAfter(newElement, targetElement) {
    var parent = targetElement.parentNode;
    if (parent.lastChild == targetElement) {
        parent.appendChild((newElement))
    } else {
        parent.insertBefore(newElement, targetElement.nextSibling);
    }
}

function stripeTables() {
    var tables = document.getElementsByTagName('table');
    for (var i = 0; i < tables.length; i++) {
        var odd = false;
        var rows = tables[i].getElementsByTagName('tr');
        for (var j = 0; j < rows.length; j++) {
            if (odd == true) {
                addClass(rows[j], 'odd');
                odd = false;
            } else {
                odd = true;
            }
        }
    }
}
function highlightRows() {
    var rows = document.getElementsByTagName('tr');
    for (var i = 0; i < rows.length; i++) {
        rows[i].oldClassName = rows[i].className;
        rows[i].onmouseover = function () {
            addClass(this, 'highlight');
        }
        rows[i].onmouseout = function () {
            this.className = this.oldClassName;
        }
    }
}
addLoadEvent(stripeTables);
addLoadEvent(highlightRows);

